home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char rcsid[] = "$Header: options.c,v 1.1 87/02/12 11:06:21 schoch Exp $";
- #endif
-
- #include "externs.h"
- #include <strings.h>
-
- dooptions()
- {
- register i;
- char *cp;
- char optbuf[128];
- u_char nopts[NOPTIONS];
-
- if (iamserver) {
- if (fgets(optbuf, sizeof optbuf, inp) == NULL)
- if (ferror(inp))
- error ("recv in dooptions");
- if (cp = index(optbuf, '\n'))
- *cp = '\0';
- if (cp = index(optbuf, '\r'))
- *cp = '\0';
- for (i = 0; optbuf[i]; i++)
- if (optbuf[i] >= '0' && optbuf[i] <= '9')
- nopts[i] = optbuf[i] - '0';
- else
- nopts[i] = UNSET;
- while (i < NOPTIONS)
- nopts[i++] = UNSET;
- for (i = 0; i < NOPTIONS; i++) {
- if (option [i] == UNSET || nopts[i] == UNSET)
- nopts[i] = option [i] = option[i] + nopts[i] - UNSET;
- if (option [i] == UNSET)
- if (i == COLOR)
- option [i] = nopts[i] = RANDOM;
- else
- option [i] = nopts[i] = TRUE;
- else if (option [i] != nopts[i])
- option [i] = nopts[i] = RANDOM;
- if (option [i] == RANDOM)
- option [i] = nopts[i] = random () & 01;
- }
- for (i = 0; i < NOPTIONS; i++)
- optbuf[i] = nopts[i] + '0';
- optbuf[i] = '\0';
- fprintf(out, "%s\r\n", optbuf);
- } else {
- for (i = 0; i < NOPTIONS; i++)
- nopts[i] = option [i];
- if (nopts[COLOR] == WHITE || nopts[COLOR] == BLACK)
- nopts[COLOR] = ! option [COLOR];
- for (i = 0; i < NOPTIONS; i++)
- optbuf[i] = nopts[i] + '0';
- optbuf[i] = '\0';
- fprintf(out, "%s\r\n", optbuf);
- if (fgets(optbuf, sizeof optbuf, inp) == NULL)
- if (errno != EINTR)
- error ("recv in dooptions");
- if (cp = index(optbuf, '\n'))
- *cp = '\0';
- if (cp = index(optbuf, '\r'))
- *cp = '\0';
- for (i = 0; optbuf[i]; i++)
- option[i] = optbuf[i] - '0';
- option [COLOR] = !(optbuf[COLOR]-'0');
- }
- ourcolor = option [COLOR];
- }
-